<html>
<head>
	<script type="text/javascript" src="/pwyl/test/web/js/unit_test_lib.js"></script>
	<script type="text/javascript" src="/pgzp/compiled/pagezipper_10.js"></script>	
	<script type="text/javascript" src="/pgzp/test/accuracy_test/test_loader.js"></script>	
</head>
<body onload="runTest()">
	
<script type="text/javascript">

//This is a big array of urls and the correct next url
//all the pages must be saved to /accuracy_test/pages
//add new pages with wget -O <filename> -k <url>
//order is [page_file_name, next_url, current_url
var bigUrlsArray = [
					["nytimes.html", "http://www.nytimes.com/slideshow/2008/10/30/travel/escapes/1031-AMERICAN_10.html", "http://www.nytimes.com/slideshow/2008/10/30/travel/escapes/1031-AMERICAN_9.html"],
					// ["icanhascheezburger.html", "http://dogs.icanhascheezburger.com/page/2/", "http://ihasahotdog.com/"],
					["makeuseof.html", "http://www.makeuseof.com/page/2/", "http://www.makeuseof.com/"],
					["redferret.html", "http://www.redferret.net/?paged=2", "http://www.redferret.net/"],
					["freecycle.html", "http://groups.freecycle.org/Desmoinesfreecycle/posts/all?page=3&resultsperpage=10&showall=off&include_offers=off&include_wanteds=off&include_receiveds=off&include_takens=off", "http://groups.freecycle.org/Desmoinesfreecycle/posts/all?page=2&resultsperpage=10&showall=off&include_offers=off&include_wanteds=off&include_receiveds=off&include_takens=off"],
					["time.html", "http://www.time.com/time/specials/2007/article/0,28804,1809858_1809957_1811552,00.html", "http://www.time.com/time/specials/2007/article/1,28804,1809858_1809957,00.html"],
					["actionsquad.html", "http://www.actionsquad.org/hammshist.htm", "http://www.actionsquad.org/hammsoverview.htm"],
					["washingtonpost.html", "http://www.washingtonpost.com/wp-dyn/content/article/2010/05/16/AR2010051603492_2.html", "http://www.washingtonpost.com/wp-dyn/content/article/2010/05/16/AR2010051603492.html"],
					["treehugger.html", "http://www.treehugger.com/files/2009/04/17-examples-of-pedal-power-and-propulsion.php?page=2", "http://www.treehugger.com/files/2009/04/17-examples-of-pedal-power-and-propulsion.php"],
					["eurogamer.html", "http://www.eurogamer.net/articles/2010-11-13-the-men-who-stare-at-protoss-article?page=2", "http://www.eurogamer.net/articles/2010-11-13-the-men-who-stare-at-protoss-article"],
					["bw.html", "http://images.businessweek.com/ss/10/01/0119_most_expensive_small_towns/3.htm", "http://images.businessweek.com/ss/10/01/0119_most_expensive_small_towns/2.htm"],
					["photoshopessentials.html", "http://www.photoshopessentials.com/photo-effects/photo-borders-photoshop-brushes/page-2.php", "http://www.photoshopessentials.com/photo-effects/photo-borders-photoshop-brushes/"],
				];
var currTestIndex = 0;


function runTest() {
	if (currTestIndex >= bigUrlsArray.length) {
		displayTests();
		return;
	}

	var currTest = bigUrlsArray[currTestIndex];
	var ifrspan = document.createElement('span');
	ifrspan.innerHTML = "<iframe id='test_page"+currTestIndex+"' onload=\"runTest2('test_page"+currTestIndex+"')\" style='clear: both; display: block;height: 200px'></iframe>";
	var ifr = ifrspan.childNodes[0];	
	document.body.appendChild(ifrspan);
	ifr.src = "/pgzp/test/accuracy_test/pages/" + currTest[0];
	ifr.style.width = (document.body.offsetWidth -5) + 'px';
}

function runTest2(ifrId) {
	var ifr = document.getElementById(ifrId);
	var pageBody = ifr.contentWindow.document.body;
	var nextPage = pgzp().buildPage(ifr.src, ifr);
	nextPage.url = bigUrlsArray[currTestIndex][2];
	pgzp().pages = [nextPage];	
	pgzp().currDomain = pgzp().getDomain(bigUrlsArray[currTestIndex][1]); //urls must be absolute
	
	var nextLinkObj = pgzp().getNextLink(pageBody);
//	alert("next link: " + nextLinkObj.url + "\nCorrect url: " + bigUrlsArray[currTestIndex][1] + "\nGot the correct url: " + (nextLinkObj.url == bigUrlsArray[currTestIndex][1]));
	assertEquals(nextLinkObj.url, bigUrlsArray[currTestIndex][1]);
	currTestIndex++;
	runTest();
}

</script>

</body></html>
